﻿using System;

namespace Extensions.Attribute.EventAttribute
{
    // 只能用于方法  并且可以被继承
    [AttributeUsage(AttributeTargets.Method,Inherited = true,AllowMultiple = true)]
    public class EventAttribute:System.Attribute
    {
        /// <summary>
        /// 事件触发的位置
        /// </summary>
        public EnumEventPosition EnumEventPosition { get; set; }
        /// <summary>
        /// 事件的名字 用来定位到事件
        /// </summary>
        public string EventName { get; set; }
        /// <summary>
        /// 事件的排序   (从大到小执行)
        /// </summary>
        public int Order { get; set; }

        public EventAttribute(string eventName,EnumEventPosition enumEventPosition,int order = 0)
        {
            this.EventName = eventName;
            this.EnumEventPosition = enumEventPosition;
            this.Order = order;
        }
        public EventAttribute(Enum eventName, EnumEventPosition enumEventPosition, int order = 0)
        {
            this.EventName = eventName.ToString();
            this.EnumEventPosition = enumEventPosition;
            this.Order = order;
        }
    }

    /// <summary>
    /// 事件位置枚举
    /// </summary>
    public enum EnumEventPosition
    {
        /// <summary>
        /// 前置
        /// </summary>
        Before,
        /// <summary>
        /// 后置
        /// </summary>
        After
    }
}
